import TauTable from '@/components/TauTable';
import React from 'react';
import { column, orderModel } from '../../stores/definitions_order';
import { useStore } from '@/hooks';
import { uniqueId } from 'lodash';
import { t } from '@lingui/macro';

const tableId = uniqueId('tauTable');

const TicketTable = (props) => {
  const { dataSource, refundInfos = [] } = props;
  const subModel = orderModel?.rsOrder?.ticketInfos[0];
  const { scTaskStore: store } = useStore();


  return (
    <>
      <TauTable
        instanceId={tableId}
        primaryKey="idx"
        size="small"
        hidePagination
        tableLayout="fixed"
        dataSource={dataSource}
        columns={[
          { title: t`序号`, dataIndex: 'idx', width: 44, cell: (v, i) => store._mainArgs.idx(i) },
          column('ticketCode', {}, subModel),
          column('state', {}, subModel),
          {
            title: t`退款状态`,
            cell: (v, i, record) => {
              const { ticketCode } = record;
              const refundInfo = refundInfos.find((item) => item.ticketCode === ticketCode) || {};
              const keys = Object.keys(refundInfo);
              let text = '无';
              if (keys.includes('refund')) {
                text = refundInfo?.refund ? '已退款' : '未退款';
              }
              return text;
            },
          },
          column('ticketPrice', {}, subModel),
        ]}
      />
    </>
  );
};

export default TicketTable;
